<template lang="html">
  <div class="addGroupBox">
    <el-row>
      <el-col :span="4">
        参与拼团产品：
      </el-col>
      <el-col :span="9"  class="text-left">
        {{$store.state.activity.gift.giveDetail.productName}}
      </el-col>
      <el-col :span="11" class="text-left">
        <span style="font-size:12px; padding-left:10px;" class="gray">产品只能单一规格；参团成功不可申请退款</span>
      </el-col>
    </el-row>
    <el-row style="margin-top:10px;">
      <el-col :span="4">
        赠送团长：
      </el-col>
      <el-col :span="9">
        <el-select v-model="tuanLeaderPrizeIds" style="width:100%;" multiple clearable size="small" placeholder="类型">
          <el-option
            v-for="item in giftList"
            :key="item.id"
            :label="item.title"
            :value="item.id">
          </el-option>
        </el-select>
      </el-col>
    </el-row>
    <el-row style="margin-top:10px;">
      <el-col :span="4">
        团长的微信推送：
      </el-col>
      <el-col :span="9">
        <el-select v-model="tuanLeaderPushId" style="width:100%;"  clearable size="small" placeholder="类型">
          <el-option
            v-for="item in giftList"
            :key="item.id"
            :label="item.title"
            :value="item.id">
          </el-option>
        </el-select>
      </el-col>
    </el-row>
    <el-row style="margin-top:10px;">
      <el-col :span="4">
        赠送团员：
      </el-col>
      <el-col :span="9">
        <el-select v-model="tuanMemberPrizeIds" style="width:100%;" multiple clearable size="small" placeholder="类型">
          <el-option
            v-for="item in giftList"
            :key="item.id"
            :label="item.title"
            :value="item.id">
          </el-option>
        </el-select>
      </el-col>
    </el-row>
    <el-row style="margin-top:10px;">
      <el-col :span="4">
        团员的微信推送：
      </el-col>
      <el-col :span="9">
        <el-select v-model="tuanMemberPushId" style="width:100%;" clearable size="small" placeholder="类型">
          <el-option
            v-for="item in giftList"
            :key="item.id"
            :label="item.title"
            :value="item.id">
          </el-option>
        </el-select>
      </el-col>
    </el-row>

    <el-row style="margin-top:10px;">
      <el-col :span="3" :offset="3" class="text-left">
        <el-button size="small" type="success" @click="sub">保存</el-button>
      </el-col>
    </el-row>
  </div>
</template>

<script>
import axios from "axios"
var url;

export default {
  props:{
    creatType:{
      dialogVisible:Boolean,
      dialogVisible2:Boolean
    }
  },
  data(){
    return {
      tuanLeaderPrizeIds:'',
      tuanLeaderPushId:[],
      tuanMemberPrizeIds:'',
      tuanMemberPushId:[],
      productId:'',
      options: [],
      giftList:[]
    }
  },
  methods:{
    sub:function (){
      var that = this,tuanLeaderPrizeIds='',tuanMemberPrizeIds='';
      if(that.tuanLeaderPrizeIds.length>0){
        for(let i=0;i<that.tuanLeaderPrizeIds.length;i++){
          tuanLeaderPrizeIds=tuanLeaderPrizeIds+that.tuanLeaderPrizeIds[i]+',';
        }
      }
      if(that.tuanMemberPrizeIds.length>0){
        for(let i=0;i<that.tuanMemberPrizeIds.length;i++){
          tuanMemberPrizeIds=tuanMemberPrizeIds+that.tuanMemberPrizeIds[i]+',';
        }
      }
      axios.get(url+"/v1/marketing/tuanGift/activity/update",{
        params:{
          activityId:that.$store.state.activity.gift.giveDetail.activityId,
          productId:that.$store.state.activity.gift.giveDetail.productId,
          tuanLeaderPrizeIds:tuanLeaderPrizeIds,
          tuanLeaderPushId:that.tuanLeaderPushId,
          tuanMemberPrizeIds:tuanMemberPrizeIds,
          tuanMemberPushId:that.tuanMemberPushId
        }
      }).then((res)=>{
        if(res.data.code==0){
          that.$message({
            showClose: true,
            message: '修改成功',
            type: 'success'
          });
          that.creatType.dialogVisible2=false;
          var json = {
            pageCount:10,
            pageIndex:1
          }
          that.$store.dispatch('getActivityGiftGiveList',json);
        }else{
          that.$message({
            showClose: true,
            message: res.data.msg,
            type: 'error'
          });
        }
      })
    },
    getProductList:function(){
      var that = this;
      axios.get(url+"/v1/product/getProductsWithOneSku",{
        params:{

        }
      }).then((res)=>{
        that.options=res.data.data;
      })
    },
    getGiftList:function (){
      var that = this;
      axios.get(url+"/v1/marketing/tuanGift/prize/all",{
        params:{

        }
      }).then((res)=>{
        that.giftList=res.data.data;
        //console.log(res.data)
      })
    }
  },
  computed:{
    getDetail(){
      return this.$store.state.activity.gift.giveDetail
    }
  },
  watch:{
    getDetail(val) {
      var arr1=[],arr2=[];
      if(this.$store.state.activity.gift.giveDetail.leaderPrizes.length>0){
        for(let i=0;i<this.$store.state.activity.gift.giveDetail.leaderPrizes.length;i++){
          arr1.push(this.$store.state.activity.gift.giveDetail.leaderPrizes[i].id)
        }
        this.tuanLeaderPrizeIds=arr1;
      }else{
        this.tuanLeaderPrizeIds=[];
      }

      if(this.$store.state.activity.gift.giveDetail.leaderPushPrize){
        this.tuanLeaderPushId=this.$store.state.activity.gift.giveDetail.leaderPushPrize.id;
      }else{
        this.tuanLeaderPushId='';
      }

      if(this.$store.state.activity.gift.giveDetail.memberPrizes.length>0){
        for(let i=0;i<this.$store.state.activity.gift.giveDetail.memberPrizes.length;i++){
          arr2.push(this.$store.state.activity.gift.giveDetail.memberPrizes[i].id)
        }
        this.tuanMemberPrizeIds=arr2;
      }else{
        this.tuanMemberPrizeIds=[];
      }

      if(this.$store.state.activity.gift.giveDetail.memberPushPrize){
        this.tuanMemberPushId=this.$store.state.activity.gift.giveDetail.memberPushPrize.id;
      }else{
        this.tuanMemberPushId='';
      }

    }
  },
  created(){
    url=this.$store.state.url;
    this.getProductList();
    this.getGiftList();
  }
}
</script>
<style>
  .addGroupBox .el-input__inner{ padding-right: 15px;}
  .addGroupBox .el-input__icon{width:25px;}
</style>
<style lang="Sass" scoped>
  .addGroupBox{}
</style>
